<?php
if($this->get('p') > 0 && isset($_POST['g'])){
	$comment = $p->getComment();
	if(isset($_POST['o']) && $_POST['o']=='json'){
		echo json_encode($comment);
		exit;
	}
}
//post comment
if(isset($_POST['pid']) && isset($_POST['submit'])){
	$comment = $p->addComment();
	// new comment posted,save the form's data
	// ignore filling the form next time.
	if(is_numeric($comment->Message)) {
		$fdata = array(
			'author'	=> htmlspecialchars(trim($_POST['username'])),
			'url'		=> htmlspecialchars(trim($_POST['url'])),
			'email'		=> htmlspecialchars(trim($_POST['email']))
		);
		cmsdream_login::save_sc(array(array('name'=>'cmsdream-comment-form','value'=>serialize($fdata),'expires'=>time() + 864000,'path'=>'/')));
	}
	if(isset($_POST['o']) && $_POST['o']=='json'){
		echo json_encode($comment);
		exit;
	}
}
